#include <vector>
#include <functional>

class FindYoungest {

    template<typename IDType>
    struct Info {
        IDType parent;
        int generation;
    };

    using IdType = int;
    std::vector<Info<IdType>> info;
    std::vector<IdType> keys;

public:
    FindYoungest(int size) : info(size) {
        keys.reserve(size);
    }

    auto add_parents_of(IdType i, IdType p) {
        info[i].parent = p;
        keys.push_back(i);
    }

    int gen_of(IdType i) {
        if (info[i].generation != 0) { return info[i].generation; }
        else {
            info[i].generation = gen_of(info[i].parent) + 1;
            return info[i].generation;
        }
    }

    auto solve_gen() {
        for (auto id : keys) {
            info[id].generation = (info[id].parent == -2) ? 1 : 0;
        }
        for (auto id : keys) { gen_of(id); }
    }

    auto get_youngests() {
        auto max_gen = 1;
        for (auto id : keys) {
            if (info[id].generation > max_gen) {
                max_gen = info[id].generation;
            }
        }

        std::vector<IdType> youngests;
        youngests.reserve(keys.size());

        for (auto id : keys) {
            if (info[id].generation == max_gen) {
                youngests.push_back(id);
            }
        }

        return youngests;
    }
};

#include <iostream>

int main() {
    int n;
    std::cin >> n;

    FindYoungest inst(n);

    for (int i = 0; i < n; ++i) {
        int val;
        std::cin >> val;
        inst.add_parents_of(i, val - 1);
    }

    inst.solve_gen();

    auto youngests = inst.get_youngests();

    if (youngests.size() > 0) {
        auto it = youngests.begin();
        std::cout << inst.gen_of(*it) << "\n";
        std::cout << (*it + 1);
        ++it;
        while (it != youngests.end()) {
            std::cout << " " << (*it + 1);
            ++it;
        }
    }
}
